<template>
  <!-- 智慧工地平台-资料管理 -->
  <popup
    :show="qualityShow"
    title="智慧工地平台-质量管理"
    @onClone="qualityFun"
  >
    <div class="qualityDialog">
      <section class="buttonBox">
        <ul>
          <li
            v-for="(item, index) in buttonList"
            :key="index"
            :class="buttonIndex == index ? 'active' : ''"
            @click="
              buttonIndex = index;
              getList();
            "
          >
            {{ item }}
          </li>
        </ul>
        <ul>
          <li
            v-for="(item, index) in ThreeMonths"
            :key="index"
            :class="dateIndex == index ? 'active' : ''"
            @click="
              dateIndex = index;
              getList();
            "
          >
            {{ item }}
          </li>
        </ul>
      </section>
      <section class="titleBox">
        <div v-if="buttonIndex == 0">
          <el-table
            :data="qualifiedList"
            style="width: 100%; height:50px,margin-top: 20px,border: 1px solid #495A79,"
            :row-style="{ height: 50 + 'px' }"
            :header-cell-style="{
              background: '#104584',
              color: '#fff',
              borderColor: '#495A79',
              height: 50 + 'px',
              padding: 0 + 'px',
            }"
            :cell-style="{
              background: '#0C2451',
              color: '#fff',
              height: 50 + 'px',
              borderColor: '#495A79',
              padding: 6 + 'px',
              cursor: 'pointer',
            }"
            @row-click="rowClick"
          >
            <el-table-column prop="noticeNumber" label="通知单编号">
            </el-table-column>
            <el-table-column prop="unqualifiedType" label="不合格项类别">
            </el-table-column>
            <el-table-column prop="unqualifiedSegment" label="不合格项环节">
            </el-table-column>
            <el-table-column prop="constructionEnterpriseName" label="施工单位名称">
            </el-table-column>
            <el-table-column prop="projectManagerName" label="项目经理名称">
            </el-table-column>
            <el-table-column prop="teamLeaderName" label="班组长名字">
            </el-table-column>
            <el-table-column prop="hasPass" label="是否已处理">
              <template slot-scope="scope">
                <span>{{
                  scope.row.hasPass == 1
                    ? "处理中"
                    : scope.row.hasPass == 2
                    ? "已完成"
                    : "未报检"
                }}</span>
              </template>
            </el-table-column>
            <!-- 0未报检 1处理中 2已完成 -->
          </el-table>
        </div>
        <div v-if="buttonIndex == 1">
          <el-table
            :data="acceptanceList"
            style="width: 100%; height:50px,margin-top: 20px,border: 1px solid #495A79,"
            :row-style="{ height: 50 + 'px' }"
            :header-cell-style="{
              background: '#104584',
              color: '#fff',
              borderColor: '#495A79',
              height: 50 + 'px',
              padding: 0 + 'px',
            }"
            :cell-style="{
              background: '#0C2451',
              color: '#fff',
              height: 50 + 'px',
              borderColor: '#495A79',
              padding: 6 + 'px',
              cursor: 'pointer',
            }"
            @row-click="rowClick"
          >
            <el-table-column prop="acceptanceNumber" label="报验单编号" width="200">
            </el-table-column>
            <el-table-column prop="unitName" label="单位工程名称">
            </el-table-column>
            <el-table-column prop="partName" label="分部工程名称">
            </el-table-column>
            <el-table-column prop="itemName" label="分项工程名称">
            </el-table-column>
            <el-table-column prop="positionName" label="验收部位名称">
            </el-table-column>
            <el-table-column prop="projectManagerName" label="项目经理名称">
            </el-table-column>
            <el-table-column prop="teamLeaderName" label="班组长名字">
            </el-table-column>
            <el-table-column prop="underCover" label="是否隐蔽工程">
              <template slot-scope="scope">
                <span>{{ scope.row.underCover == 1 ? "是" : "否" }}</span>
              </template>
            </el-table-column>
            <!-- 0否 1是 -->
          </el-table>
        </div>
      </section>
      <section class="pagination">
        <select v-model="selected" @change="selectChange">
          <option
            v-for="(option, idx) in options"
            :key="idx"
            :value="option.value"
          >
            {{ option.text }}
          </option>
        </select>
        <MoPaging
          :page-index="currentPage"
          :total="count"
          :page-size="pageSize"
          @pageChange="pageChange"
        >
        </MoPaging>
        <div class="pege">
          跳至
          <input type="tel" v-model="page" @blur="inputBlur" />
          页
        </div>
      </section>
    </div>
  </popup>
</template>

<script>
import popup from "../../popup.vue";
import MoPaging from "../mo-paging.vue";
import api from "@/util/api";
import * as dayjs from "dayjs";
export default {
  components: {
    popup,
    MoPaging,
  },
  name: "qualityDialog",
  data() {
    return {
      qualityDialog: `<div>1111111111</div>`,
      buttonList: ["不合格项通知单", "三级验收表"],
      buttonIndex: 0,
      ThreeMonths: [],
      dateIndex: 0,
      qualifiedList: [],
      acceptanceList: [],
      tableData: [],
      page: 1,
      pageSize: 5, //每页显示10条数据
      currentPage: 1, //当前页码
      count: 100, //总记录数,
      selected: 5,
      options: [
        { text: "5条/页", value: 5 },
        { text: "7条/页", value: 7 },
        { text: "9条/页", value: 9 },
      ],
    };
  },
  mounted() {
    this.getThreeMonths();
  },
  watch: {},
  computed: {
    qualityShow: function () {
      return this.$store.state.qualityShow;
    },
  },
  methods: {
    qualityFun(data) {
      let that = this;
      that.$store.dispatch("changeFun", {
        str: "qualityShow",
        cont: data,
      });
    },
    // 该行被点击
    rowClick(row, column, event) {
      this.$store.dispatch('changeFun',{
        str: 'threeLevelShow',
        cont: true
      })
      this.$store.dispatch("changeFun", {
        str: "threeLevel",
        cont: {
          type: this.buttonIndex?'acceptance':'unQualified',
          id: row.id
        },
      });
    },
    //从page组件传递过来的当前page
    pageChange(page) {
      this.currentPage = page;
      this.page = page;
      this.getList();
    },
    // 每页条数改变
    selectChange() {
      this.pageSize = this.selected;
      this.getList();
    },
    // 当前页改变
    inputBlur() {
      // this.currentPage = this.page
      this.pageChange(+this.page);
    },

    // 时间切换
    getList() {
      if (this.buttonIndex) {
        this.getAcceptanceList();
      } else {
        this.getUnQualifiedList();
      }
    },
    /** API */
    // 获取近三个月时间
    getThreeMonths() {
      api.getThreeMonths({}, (res) => {
        res.data.data.map((item) => {
          this.ThreeMonths.push(dayjs(item).format("YYYY-MM"));
        });
        console.log(this.ThreeMonths);
        this.getUnQualifiedList();
        this.getAcceptanceList();
      });
    },
    // 大屏二级展示数据:不合格项列表
    getUnQualifiedList() {
      api.getUnQualifiedList(
        {
          month: this.ThreeMonths[this.dateIndex],
          pageNum: this.currentPage,
          pageSize: this.pageSize,
        },
        (res) => {
          this.qualifiedList = res.data.list;
          this.count = res.data.total;
        }
      );
    },
    // 大屏二级展示数据:报验项列表
    getAcceptanceList() {
      api.getAcceptanceList(
        {
          month: this.ThreeMonths[this.dateIndex],
          pageNum: this.currentPage,
          pageSize: this.pageSize,
        },
        (res) => {
          this.acceptanceList = res.data.list;
          this.count = res.data.total;
        }
      );
    },
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less">
.qualityDialog {
  width: 1200px;
  height: 680px;
  overflow: auto;
  .buttonBox {
    width: 100%;
    height: auto;
    padding-bottom: 30px;
    display: flex;
    justify-content: space-between;
    ul {
      display: flex;
      justify-content: space-between;
      color: #fff;
      li {
        list-style-type: none;
        height: 43px;
        background-color: #135ba7;
        border-radius: 4px;
        text-align: center;
        line-height: 43px;
        margin-left: 12px;
        padding: 0 14px;
      }
      li:nth-child(1) {
        margin: 0;
      }
      .active {
        background-color: #ff891d;
      }
    }
  }
  .pagination {
    width: fit-content;
    margin: 0 auto;
    padding-top: 10px;
    select {
      width: 95px;
      height: 40px;
      border: 1px solid #e6ecf3;
      border-radius: 2px;
      margin-left: 12px;
      padding-left: 12px;
      line-height: 40px;
      font-size: 15px;
      text-align: center;
      color: #fff;
      overflow: hidden;
      background-color: #00000000;
      option {
        color: #000;
      }
    }
    .pege {
      display: inline-block;
      color: #fff;
      font-size: 15px;
      input {
        width: 63px;
        height: 40px;
        color: #fff;
        border: 1px solid #e6ecf3;
        border-radius: 2px;
        padding-left: 6px;
        background-color: #00000000;
        box-sizing: border-box;
      }
    }
  }
}
.el-table--border::after,
.el-table--group::after,
.el-table::before {
  background-color: #495a79 !important;
}
.el-table .el-table__body-wrapper .el-table__empty-block {
  background-color: #135ba7 !important;
}
</style>

